home *** CD-ROM | disk | FTP | other *** search
/ Apple II Magazines (PO) / Nibble Volume 10, No. 06 (1989-06)(MindCraft Publishing)(Side A).zip / Nibble Volume 10, No. 06 (1989-06)(MindCraft Publishing)(Side A).po / SMARTBOOT.S < prev    next >
Text File  |  1996-12-24  |  11KB  |  340 lines

  1. ********************************
  2. * SmartBoot Source Code        *
  3. * by Steve Stephenson          *
  4. * Copyright (C) 1989           *
  5. * MicroSPARC, Inc.             *
  6. * Concord, MA 01742            *
  7. *                              *
  8. * Merlin-16 Assembler          *
  9. ********************************
  10.  
  11.           TR ON          ;TRuncate object to 4 bytes
  12.           TR ADR         ;TRuncate ADdRess to lo word
  13.           XC             ;enable eXteneded opCodes
  14.  
  15. Cmd       = $42          ;command (0=status, 1=rd, 2=wrt, 3=fmt)
  16. UnitNum   = $43          ;DSSS000 slot (S)/ drive (D)
  17. DataBufr  = $44,45       ;pointer to data buffer
  18. BlkNum    = $46,47       ;block number
  19. SlotROM   = $48,49       ;pointer to the interface card entry
  20. Dir       = $4A,4B       ;pointer for finding file entries
  21. LwrHalf   = $4A,4B       ;pointer to 1st page of the block
  22. UprHalf   = $4C,4D       ;pointer to 2nd page of the block
  23. P16:SYS:P8 = $4C         ;flag for which file seeking
  24. BlksToDo  = $4D          ;counter of blocks in directory
  25. BlksDone  = $4E          ;counter of blocks searched
  26. BlkIndex  = $4E          ;index to which block being read
  27. RawBuffer = $50,51       ;pointer to raw data buffer
  28. KeyBlkBuf = $1E00,1FFF   ;key block buffer
  29. PowerUp   = $03F4        ;warm or cold reset check
  30. Home      = $FC58        ;monitor clear/home routine
  31. sapling   = $02*$10      ;storage type for sapling file
  32. dirtype   = $0D*$10      ;storage type for directory
  33.  
  34. *===============================
  35.           ORG $0800
  36.  
  37.           dfb 01         ;signature {required}
  38. Start
  39.           stx UnitNum    ;save slot * 16
  40.           txa            ;make $Csxx
  41.           and #$70
  42.           lsr
  43.           lsr
  44.           lsr
  45.           lsr
  46.           ora #$C0
  47.           sta SlotROM+1  ;set (SlotROM) = $CsFF
  48.           ldy #$FF
  49.           sty SlotROM
  50.           iny            ;y=0
  51.           lda (SlotROM),y ;get re-entry offset from CsFF
  52.           beq ToError    ;if 0 it's a Disk II (unsupported)
  53.  
  54.           sta SlotROM    ;else, finish addr setup $Csxx
  55.           sty BlkNum+1   ;hi byte of block number = 0
  56.           sty P16:SYS:P8 ;preset flag for SYSTEM/P8
  57.           iny            ;setup for root dir read..
  58.           sty Cmd        ; cmd=1=read
  59.           iny
  60.           sty BlkNum     ; blk=2
  61.  
  62.           jsr Home       ;monitor clr screen
  63.           ldy Msg0       ;print title message
  64.           dey
  65. :printlp  lda Msg0+1,y   ;poke the string
  66.           sta $0528,y    ; to the ctr of the scrn
  67.           dey
  68.           bpl :printlp
  69.  
  70.           jsr Test       ;pass=0; fail=non0
  71.           beq OpenDir    ;pass, stay set for P16
  72.           dec P16:SYS:P8 ;fail, dec for P8
  73.  
  74. *-------------------------------
  75. * P16:SYS:P8 flag :
  76. * ff = seeking PRODOS
  77. * 00 = seeking SYSTEM/
  78. * 01 = seeking P8
  79. *-------------------------------
  80. * setup two zpage pointer pairs to read the blocks into
  81. OpenDir
  82.           lda #>$2000    ;read into memory from $2000 up
  83.           sta RawBuffer+1
  84.           sta Dir+1
  85.           stz RawBuffer
  86.           stz Dir
  87.           stz BlksDone   ;clr the counters
  88.           stz BlksToDo
  89.  
  90. *-------------------------------
  91. * read the entire directory into memory
  92. * first time read the volume dir (to search for PRODOS)
  93. * second time read the SYSTEM/ dir (to search for P8)
  94. ReadDir
  95.           inc BlksToDo   ;keep count of how many there are
  96.           jsr ReadBlock  ;read dir block into bufr
  97.           bcc :noerr
  98.           jmp Error      ;standard error handling
  99. :noerr
  100.           ldy #2         ;point to next block link
  101.           lda (RawBuffer),y
  102.           sta BlkNum     ; get the next blk number
  103.           iny
  104.           lda (RawBuffer),y
  105.           sta BlkNum+1
  106.           ora BlkNum     ;see if we're done
  107.           beq NewBlk     ; link=0000=no more blocks.
  108.  
  109.           inc RawBuffer+1 ;else, bump destination
  110.           inc RawBuffer+1 ; up 2 pages and
  111.           bra ReadDir    ; keep reading
  112.  
  113. *-------------------------------
  114. * bump pointer to next file name; check for end of block;
  115. * and end of directory.
  116. NxtEntry
  117.           lda Dir        ;adjust the current pointer
  118.           clc
  119.           adc #$27       ; by the length of an entry
  120.           sta Dir
  121.           bcc :1st_half  ;see if we've crossed into
  122.           inc Dir+1      ; the second half of the blk
  123. :1st_half
  124.           cmp #$FF       ;at end of the blk?
  125.           bne SameBlk    ; no, still in this blk
  126.  
  127.           inc Dir+1      ;yes, reset to next blk
  128.           inc BlksDone   ; bump counter
  129.           lda BlksDone   ; and check for
  130.           cmp BlksToDo   ; end of directory
  131. ToError   beq Error      ;end of buffer; not found.
  132.                          ;(also relay from floppy)
  133. *-------------------------------
  134. * Enter here after reading all of the linked dir blocks
  135. * into memory to begin the search in the first blk;
  136. * or fall here from above to search the next block.
  137. NewBlk
  138.           lda #4         ;start pointer just past links
  139.           sta Dir
  140. SameBlk
  141.           lda P16:SYS:P8 ;looking for which?
  142.           bmi :Prodos    ;ff
  143.           bne :P8        ;01
  144. :System                  ;00
  145.           jsr FindSystem ;looking for 'SYSTEM'
  146.           bne NxtEntry   ; not found yet...
  147.           beq Found
  148. :P8
  149.           jsr FindP8     ;looking for 'P8'
  150.           bne NxtEntry
  151.           beq Found
  152. :Prodos
  153.           jsr FindProdos ;looking for 'PRODOS'
  154.           bne NxtEntry
  155.  
  156. *-------------------------------
  157. * When the respective 'find' routine finds it's file,
  158. * it also checks the the storage type and file type;
  159. * Y is left pointing at the file type...
  160. Found
  161.           iny            ;so, bump to point to key block
  162.           lda (Dir),y    ;get the key blk and
  163.           sta BlkNum     ; setup for next read
  164.           iny
  165.           lda (Dir),y
  166.           sta BlkNum+1
  167.  
  168.           lda P16:SYS:P8 ;which are we doing?
  169.           bmi GetKeyBlk  ;read in key block of PRODOS
  170.           bne GetKeyBlk  ; or of P8
  171.  
  172.           inc P16:SYS:P8 ;else, change flag and
  173.           bra OpenDir    ; search for P8 now.
  174.  
  175. *-------------------------------
  176. * We now know which blk is the key blk, so setup
  177. * to read it into the 2 page area just below $2000
  178. GetKeyBlk
  179.           lda #<KeyBlkBuf ;set pointers to $1E00
  180.           sta LwrHalf    ; to read the key block
  181.           sta UprHalf
  182.           ldy #>KeyBlkBuf ;set pointers to both
  183.           sty LwrHalf+1  ; upper and lower pages
  184.           sty RawBuffer+1 ; of the blk for easier
  185.           iny            ; indexing of the blks
  186.           sty UprHalf+1
  187.           stz BlkIndex   ;clr the blk-to-do index
  188.  
  189. *-------------------------------
  190. * 1st read gets the key block into the buffer 2 pages
  191. * below $2000; subsequent reads dig out the block number
  192. * from this key blk buffer and put the blks into memory
  193. * starting at $2000.
  194. ReadFile
  195.           jsr ReadBlock  ;dest addr and blknum set
  196.           bcs Error
  197.           inc RawBuffer+1 ;bump destination
  198.           inc RawBuffer+1
  199.           ldy BlkIndex   ;set index to find which blk
  200.           inc BlkIndex
  201.           lda (LwrHalf),y ;lookup a blk in the list
  202.           sta BlkNum
  203.           lda (UprHalf),y
  204.           sta BlkNum+1
  205.           ora (LwrHalf),y ;if 00 then we're done
  206.           bne ReadFile   ;else read in another
  207.  
  208.           jmp $2000      ;now run it.
  209.  
  210. *===============================
  211. * Subroutines
  212. *===============================
  213. Error
  214.           jsr Home       ;monitor clr screen
  215.           ldy Msg1       ;length of msg
  216.           dey
  217. :printlp  lda Msg1+1,y   ;poke the string
  218.           sta $05AE,y    ; to the ctr of the scrn
  219.           dey
  220.           bpl :printlp
  221.           dec PowerUp    ;setup reset to cause reboot
  222. :hang     jmp :hang      ;then lock up.
  223.  
  224. *===============================
  225. * is this entry "SYSTEM/"?
  226. FindSystem
  227.           lda System     ;start with length/storage type
  228.           and #$0F       ; strip to file name length
  229.           tay
  230. :namelp   lda (Dir),y    ;does this character
  231.           cmp System,y   ; match what we want?
  232.           bne :nomatch   ;no, next name.
  233.           dey            ;yes, keep matching characters
  234.           bpl :namelp
  235.                          ;it's a match!
  236. :chktype                 ;A holds length/storage type
  237.           and #$F0       ; strip to just storage type
  238.           cmp #dirtype   ;proper type?
  239.           bne Error      ;good name + bad type = bad news
  240.  
  241.           ldy #$10       ;reset to point to
  242.           lda (Dir),y    ; the file type
  243.           cmp #$0F       ; is it directory?
  244.           bne Error      ;'file type mismatch'
  245. :nomatch
  246.           rts
  247.  
  248. *===============================
  249. * is this entry "P8"?
  250. FindP8
  251.           lda P8
  252.           and #$0F
  253.           tay
  254. :namelp   lda (Dir),y
  255.           cmp P8,y       ;match?
  256.           bne nomatch    ;no, next name
  257.           dey
  258.           bpl :namelp
  259.  
  260. ChkType
  261.           and #$F0       ;storage type
  262.           cmp #sapling
  263.           bne Error
  264.  
  265.           ldy #$10
  266.           lda (Dir),y    ;file type
  267.           cmp #$FF       ; system?
  268.           bne Error
  269. nomatch
  270.           rts
  271.  
  272. *===============================
  273. * is this entry "PRODOS"?
  274. FindProdos
  275.           lda Prodos
  276.           and #$0F
  277.           tay
  278. :namelp   lda (Dir),y
  279.           cmp Prodos,y   ;match?
  280.           bne nomatch    ;no, next name
  281.           dey
  282.           bpl :namelp
  283.           bra ChkType    ;common exit
  284.  
  285. *===============================
  286. * use the interface card rom code to read a block
  287. * enter with command and block number already set
  288. * then finish passing the destination address
  289. ReadBlock
  290.           lda RawBuffer
  291.           sta DataBufr
  292.           lda RawBuffer+1
  293.           sta DataBufr+1
  294.           jmp (SlotROM)  ;returns to ReadBlock caller
  295.  
  296. *===============================
  297. System    dfb dirtype+lenSystem ;storage type & length
  298. ]name     asc 'SYSTEM'
  299. lenSystem = *-]name      ; calculate name length
  300. *-------------------------------
  301. P8        dfb sapling+lenP8
  302. ]name     asc 'P8'
  303. lenP8     = *-]name
  304. *-------------------------------
  305. Prodos    dfb sapling+lenProdos
  306. ]name     asc 'PRODOS'
  307. lenProdos = *-]name
  308. *-------------------------------
  309. *===============================
  310. * The Test: it could be just about anything...
  311. * In this case, make sure it's a GS then
  312. * decide based on the state of the caps lock key
  313. Test
  314.           sec            ;standard GS test
  315.           jsr $FE1F      ; is it a GS?
  316.           bcc GS         ;yes ->
  317.  
  318.           jsr Home       ;monitor clr screen
  319.           ldy Msg2       ;length of msg
  320.           dey
  321. :printlp  lda Msg2+1,y   ;poke the string
  322.           sta $05AE,y    ; to the ctr of the scrn
  323.           dey
  324.           bpl :printlp
  325.           dec PowerUp    ;setup reset to cause reboot
  326. :hang     jmp :hang      ;then lock up.
  327.  
  328. * all of that for this ?
  329. GS
  330.           lda $C025      ;keyboard modifier
  331.           and #%00000100 ; caps lock bit
  332.           eor #%00000100 ; if caps lock then Z=1
  333.           rts
  334.  
  335. Msg0      str "SmartBoot 8/16  (C)1989 MicroSPARC, Inc."
  336. Msg1      str "*** Unable To Load ProDOS ***"
  337. Msg2      str "*** REQUIRES AN APPLE IIGS ***"
  338.  
  339. end       ds \           ;pad to $09FF
  340.